package com.xuhai.blog.admin.controller;


import com.xuhai.blog.admin.entity.CategoryEntity;
import com.xuhai.blog.admin.service.CategoryService;
import com.xuhai.blog.common.util.ResultJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 文章分类表 前端控制器
 * </p>
 *
 * @author 机蜂
 * @since 2022-02-08
 */
@RestController
@RequestMapping("/admin/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/page")
    public ResultJson page(int page, int limit, CategoryEntity category){
        return ResultJson.ok().data(categoryService.getPage(page, limit, category));
    }

    @GetMapping("/info/{categoryId}")
    public ResultJson info(@PathVariable Integer categoryId){
        return ResultJson.ok().data(categoryService.getById(categoryId));
    }

    @PostMapping("/update")
    public ResultJson update(@RequestBody CategoryEntity category){
        categoryService.saveOrUpdate(category);
        return ResultJson.ok();
    }

    @DeleteMapping("/delete/{categoryId}")
    public ResultJson delete(@PathVariable Integer categoryId){
        categoryService.deleteInfo(categoryId);
        return ResultJson.ok();
    }
}

